package com.dexgdx.game.factory;

import com.dexgdx.game.Game;
import com.dexgdx.game.constants.EMoveDirection;
import com.dexgdx.game.constants.EPlayerType;
import com.dexgdx.game.json.JSONActor;
import com.dexgdx.game.structure.actor.AbstractActor;
import com.dexgdx.game.structure.actor.EnemyActor;
import com.dexgdx.game.structure.actor.PlayerActor;
import com.dexgdx.game.structure.base.BaseRegion;

public class ActorFactory {

	public static AbstractActor loadFromJSONActor(JSONActor jSONActor){
		
		AbstractActor actor = null;
		BaseRegion region = null;
		
		if(jSONActor.isSimpleActorRegion()){
			region = new BaseRegion(jSONActor.getX(), jSONActor.getY(), 
					Game.defaultConstants.getActorRingHeight(), Game.defaultConstants.getActorRingWidth());
		}
		else {
			region = new BaseRegion(jSONActor.getX(), jSONActor.getY(), jSONActor.getHeight(), jSONActor.getWidth());
		}
		
		float movementSpeed = jSONActor.getMovementSpeed() == -1 ? 
				Game.defaultConstants.getPlayerSpeed() : jSONActor.getMovementSpeed();
		
		EMoveDirection eMoveDirection = jSONActor.getMoveDirection() == null ? 
				EMoveDirection.SOUTH : EMoveDirection.valueOf(jSONActor.getMoveDirection());
		
		if(jSONActor.getPlayerType() == EPlayerType.ENEMY){
			actor = new EnemyActor(jSONActor.getImagePath(), region.x, region.y, 
					region.height, region.width, movementSpeed, jSONActor.getPlayerIdentification());
		}
		else {
			actor = new PlayerActor(jSONActor.getImagePath(), region.x, region.y, 
					region.height, region.width, movementSpeed, jSONActor.getPlayerIdentification());
		}

		actor.setMoveDirection(eMoveDirection);
		
		return actor;
	}
}
